package com.newtouch.ainsurtech.service.demo.impl;


import com.newtouch.ainsurtech.entity.demo.PersonEntity;
import com.newtouch.ainsurtech.repository.demo.PersonEntityRepository;
import com.newtouch.ainsurtech.service.AbstractService;
import com.newtouch.ainsurtech.service.demo.PersonEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2016
 * All rights reserved. 2017-09-26 19:35
 * </p>
 *
 * @author MaoJiaWei
 * @version 1.0
 */
@Service
public class PersonEntityServiceImpl extends AbstractService implements PersonEntityService {
    @Autowired
    private PersonEntityRepository repository;

    /**
     * 根据GridPage对象按分页查找服务
     *
     * @param page 分页对象，里有关键字keyWord,供模糊匹配
     * @return 分页结果数据对象集合
     */
    @Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
    public Page<PersonEntity> pagingBy(String name,Pageable page) {
        return repository.findAll(page);
    }

    /**
     * 保存
     *
     * @param object
     */
    @Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
    public void save(PersonEntity object) {
        repository.save(object);
    }

    /**
     * 批量删除
     *
     * @param objectList
     */
    @Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
    public void delete(List<PersonEntity> objectList) {
        repository.delete(objectList);
    }

    /**
     * 删除
     *
     * @param object
     */
    @Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
    public void delete(PersonEntity object) {

        repository.delete(object);
    }

    /**
     * 根据主键删除
     *
     * @param id
     */
    @Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
    public void delete(Long id) {
       repository.delete(id);
    }

    /**
     * 更新
     *
     * @param object
     */
    @Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
    public void update(PersonEntity object) {
        repository.save(object);
    }

    /**
     * 根据主键查询
     *
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class, timeout = 30, propagation = Propagation.REQUIRED)
    public PersonEntity get(Long id) {
        return repository.findById(id);
    }
}
